<!DOCTYPE html>
<html>

<head>
    <title>课程中心</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <!-- head 中 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.2/style/weui.min.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.0/css/jquery-weui.min.css">

    <link href="../css/main.css" rel="stylesheet" />

</head>

<body>
    <div class="nav">
        <span onclick="history.go(-1)">
            <img src="../img/arrow-left.png" />
        </span>
        <span>课程中心</span>
        <span id="btn-nav">导航</span>
    </div>
    <div class="weui-skin_android" id="androidActionsheet" style="display:none">
        <div class="weui-mask" style="visibility:visible; opacity:0.5"></div>
        <div class="weui-actionsheet">
            <div class="weui-actionsheet__menu">
                <div class="weui-actionsheet__cell" onclick="location.href='index.html'">课程中心</div>
                <!-- <div class="weui-actionsheet__cell" onclick="location.href='map.html'">党建大数据</div>
                <div class="weui-actionsheet__cell" onclick="location.href = 'http://39.104.67.0:8443/ehome/ehome.html'">党群E家</div> -->
                <div class="weui-actionsheet__cell" onclick="location.href='center.html'">考试中心</div>
                <!-- <div class="weui-actionsheet__cell" onclick="location.href='jianguan.html'">驻村云监管</div>
                <div class="weui-actionsheet__cell" onclick="location.href = 'http://39.104.67.0:8443/ehome/personnel.html'">人才直通车</div> -->
                <div class="weui-actionsheet__cell" onclick="location.href='user.html'">个人信息</div>
            </div>
        </div>
    </div>

    <div class="panel detail">

        <div class="panel-body">
            <div class="card-alert">
                <div class="alert-title" id="title">强化思想入党，掌握党，基本知识</div>
                <div class="alert-body">
                    <div class="item">
                        <img src="../img/kecheng3.png" />
                        <span>课时数：<span id="period"></span></span>
                    </div>
                    <div class="item">
                        <img src="../img/kecheng31.png" />
                        <span>课程作者：<span id="author"></span></span>
                    </div>

                    <div class="item">
                        <img src="../img/kecheng33.png" />
                        <span>本期内容：<span id="memo"></span></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="panel-body">
            <div style="display:none" id="encode-content"></div>
            <div class="content">
                <!--<p>军警民联合编队航行途中。潘新新摄

                初夏清晨，当第一缕阳光洒向海面，西沙某水警区军医钟俊利就起床了。

                当天，钟俊利将跟随一支特殊巡逻编队，对西沙海域进行联合巡逻。一周前，得知自己即将参与任务，他兴奋不已：“能够参加军警民首次在西沙海域开展联合巡逻，是一生的荣耀！”</p>
                                <img src="../img/item2.png" />
                                <p>军警民联合编队航行途中。潘新新摄

                初夏清晨，当第一缕阳光洒向海面，西沙某水警区军医钟俊利就起床了。

                当天，钟俊利将跟随一支特殊巡逻编队，对西沙海域进行联合巡逻。一周前，得知自己即将参与任务，他兴奋不已：“能够参加军警民首次在西沙海域开展联合巡逻，是一生的荣耀！”</p>
                                <img src="../img/item1.png" />
                                <p>军警民联合编队航行途中。潘新新摄

                初夏清晨，当第一缕阳光洒向海面，西沙某水警区军医钟俊利就起床了。

                当天，钟俊利将跟随一支特殊巡逻编队，对西沙海域进行联合巡逻。一周前，得知自己即将参与任务，他兴奋不已：“能够参加军警民首次在西沙海域开展联合巡逻，是一生的荣耀！”</p>-->
            </div>
        </div>

        <div class="panel detail comments">
            <div id="questions_title_div"></div>
            <div id="choseList"></div>
            <div id="judgeList"></div>
            <div id="btn_test_div"></div>
            <a class="weui-btn weui-btn_primary" onClick="goToTest()" href="javascript: void(0);">去考试</a>
            <!-- <br /><br /> -->
        </div>

    </div>
    <!-- <div class="panel detail comments">

        <div class="panel-body">
            <div class="card-alert">
                <div class="alert-title">讨论区</div>
                <div class="alert-body">
                    <div class="item">
                        <div class="user"><div><img src="../img/p111.jpg" />&nbsp; 张小佳</div>   <span>2018-08-08 15:35</span></div>
                        <p>好好学习，天天向上,提高自己的素质与能力。</p>
                    </div>
                </div>
            </div>
        </div>

        <div class="panel-body">
            <div class="card-alert">

                <div class="alert-body">
                    <div class="item">
                        <div class="user"><div><img src="../img/p111.jpg" />&nbsp; 王小李</div>   <span>2017-10-06 09:55</span></div>
                        <p>好好学习，天天向上,提高自己的素质与能力。</p>
                    </div>
                </div>
            </div>
        </div>


    </div> -->

    <!--<a href="javacsript:void(0)" id="goToTest" class="weui-btn weui-btn_primary btn-bottom-fixed">去考试</a>-->


    <!-- body 最后 -->
    <script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js" type='text/javascript' charset='utf-8'></script>
    <script src="https://cdn.bootcss.com/jquery-weui/1.2.0/js/jquery-weui.min.js" type='text/javascript' charset='utf-8'></script>
    <script src="https://g.alicdn.com/dingding/open-develop/1.9.0/dingtalk.js" type='text/javascript' charset='utf-8'></script>
    <script src="../scripts/main.js"></script>
    <!-- Initialize Swiper -->
    <script>

        var userInfo = {};
        var url = window.location.href;
        var id = GetQueryString("id");


        function goToTest() {
	        window.location.href = "goTest.html";
        }


        function setUserInfo(info) {
            userInfo = info;
            // alert(JSON.stringify(userInfo));

            $.ajax({
                url: "http://localhost:8222/studyResult",
                method: "Post",
                data: {
                    user_id: userInfo.emplId,
                    article_id: id
                },
                success: function (res) {
                    console.log(res);
                }
            });

        }


        var questions_title_html = '<div class="panel-body">' +
            '<div class="card-alert">' +
            '<div class="alert-title" id="questions_title" >课后练习题</div>' +
            '</div>' +
            '</div>';

        var btn_test_html = '<div class="weui-panel__bd" style="padding:20px;">' +
            '<button id="btn-test" class="weui-btn weui-btn_default" onClick="uploadTest()">提交练习</button>' +
            '</div>';
        var cHtml = '<div class="weui-panel weui-panel_access test">' +
            '<div class="weui-panel__hd">一、单选题</div>' +
            '<div class="weui-panel__bd">' +
            '<span href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">' +
            '   <div class="weui-media-box__bd"><img id="img_{{id}}" src="../img/right.png" class="right" style="display:none" />' +
            '      <p class="weui-media-box__desc" answer="{{answer}}">{{no}}. {{question}}:   </p>' +
            '     <div class="weui-cells weui-cells_radio">' +
            '        <label class="weui-cell weui-check__label" for="x1{{id}}">' +
            '           <div class="weui-cell__bd">' +
            '              <p>A. {{answerA}}</p>' +
            '         </div>' +
            '        <div class="weui-cell__ft">' +
            '           <input type="radio" name="radio_{{id}}" class="weui-check" value="A" id="x1{{id}}">' +
            '          <span class="weui-icon-checked"></span>' +
            '     </div>' +
            '</label>' +
            ' <label class="weui-cell weui-check__label" for="x12{{id}}">' +
            '    <div class="weui-cell__bd">' +
            '       <p>B. {{answerB}}</p>' +
            '  </div>' +
            ' <div class="weui-cell__ft">' +
            '        <input type="radio" name="radio_{{id}}" class="weui-check" value="B" id="x12{{id}}">' +
            '       <span class="weui-icon-checked"></span>' +
            '  </div>' +
            '         </label>' +
            '        <label class="weui-cell weui-check__label" for="x13{{id}}">' +
            '           <div class="weui-cell__bd">' +
            '              <p>C. {{answerC}}</p>' +
            '         </div>' +
            '        <div class="weui-cell__ft">' +
            '           <input type="radio" name="radio_{{id}}" class="weui-check"  value="C" id="x13{{id}}">' +
            '          <span class="weui-icon-checked"></span>' +
            '     </div>' +
            '               </label>' +
            '              <label class="weui-cell weui-check__label" for="x14{{id}}">' +
            '                 <div class="weui-cell__bd">' +
            '                    <p>D. {{answerD}}</p>' +
            '               </div>' +
            '              <div class="weui-cell__ft">' +
            '                 <input type="radio" name="radio_{{id}}" class="weui-check" value="D" id="x14{{id}}">' +
            '                <span class="weui-icon-checked"></span>' +
            '           </div>' +
            '      </label>' +
            ' </div>' +
            '<p class="answer_p" id="answer_{{id}}" style="display:none" >  答案 {{result}}}</p>' +
            '      </div>' +
            ' </span>' +
            ' </div>' +
            ' </div>';

        var jHtml = '<div class="weui-panel weui-panel_access test">' +
            '<div class="weui-panel__hd">{{panduanQuestionTypeIndex}}、判断题</div>' +
            '<div class="weui-panel__bd">' +
            '<span href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">' +
            '<div class="weui-media-box__bd" ><img id="img_{{id}}" src="../img/wrong.png" class="right" style="display:none" />' +
            '   <p class="weui-media-box__desc" answer="{{answer}}">{{no}}. {{question}}:</p>' +
            '  <div class="weui-cells weui-cells_radio">' +
            '     <label class="weui-cell weui-check__label" for="y{{id}}">' +
            '        <div class="weui-cell__bd">' +
            '           <p>A. V</p>' +
            '      </div>' +
            '     <div class="weui-cell__ft">' +
            '                                <input type="radio" class="weui-check" name="radio_{{id}}" value="V"  id="y{{id}}">' +
            '                               <span class="weui-icon-checked"></span>' +
            '                          </div>' +
            '                     </label>' +
            '                    <label class="weui-cell weui-check__label" for="y2{{id}}">' +
            '                            <div class="weui-cell__bd">' +
            '                                <p>B. X</p>' +
            '                           </div>' +
            '                          <div class="weui-cell__ft">' +
            '                                <input type="radio" name="radio_{{id}}" class="weui-check" value="X" id="y2{{id}}">' +
            '                               <span class="weui-icon-checked"></span>' +
            '                          </div>' +
            '                     </label>' +
            '                </div>' +
            '<p class="answer_p" id="answer_{{id}}" style="display:none" >  答案 {{result}}}</p>' +
            '           </div>' +
            '      </span>' +
            ' </div>' +
            ' </div>';

        var questions = [];


        $(function () {

        	var rel = {
		        "article_id": 2,
		        "article_fid": 0,
		        "title": "必修课01",
		        "content": "&lt;p&gt;阿斯蒂芬发送到发送到发&lt;/p&gt;",
		        "abstract": "必修课01必修课01必修课01",
		        "status": 1,
		        "recommend": 0,
		        "coursetype": 2,
		        "credit": 0,
		        "period": 3,
		        "author": "晓伟",
		        "source": "",
		        "cover": "http://7xrsfo.com1.z0.glb.clouddn.com/123.jpeg",
		        "urls": [],
		        "comment": 0,
		        "banner": 0,
		        "user_id": "undefined",
		        "dept_id": 1,
		        "pubtime": "2018-08-13 11:20:24",
		        "updated": "2018-08-13 11:21:17",
		        "created": "2018-08-13 11:21:17",
		        "type_ids": [
			        {
				        "at_id": 2,
				        "article_id": 2,
				        "type_id": 1,
				        "type_name": "信息上报"
			        }
		        ]
	        };

	        $("#title").html(rel.title);
	        $("#period").html(rel.period);
	        $("#author").html(rel.author);
	        $("#memo").html(rel.abstract);
	        $("#encode-content").html(rel.content);
	        $(".content").html($("#encode-content").text());

            getUserInfo(url, setUserInfo);


            $("#goToTest").on("click", function () {

                location.href = 'test.html?ep_id=22&user_id=' + userInfo.emplId;
            });


            $.get("http://localhost:8222/article/" + id, function (rel) {

                $("#title").html(rel.title);
                $("#period").html(rel.period);
                $("#author").html(rel.author);
                $("#memo").html(rel.abstract);
                $("#encode-content").html(rel.content);
                $(".content").html($("#encode-content").text());
            });

            $.get("http://localhost:8222/article/" + id + "/question", function (rel) {

                questions = rel.rows;
                console.log('------------------')
                console.log(questions)
                if (questions.length !== 0) {
                    var qArr = []
                    qArr.push(questions_title_html)
                    var btnArr = []
                    btnArr.push(btn_test_html)
                    $("#questions_title_div").html(qArr.join(""));
                    $("#btn_test_div").html(btnArr.join(""));
                }
                var chosehtml = [];
                var html = [];
                var jcount = 0;
                var cCount = 0;
                var panduanQuestionTypeIndex = getPanduanQuestionTypeIndex(rel.rows)
                for (var i = 0; i < rel.rows.length; i++) {

                    if (rel.rows[i].eqt_id == 1) {
                        html.push(
                            jHtml.replace("{{question}}", rel.rows[i].question)
                                .replace("{{panduanQuestionTypeIndex}}", panduanQuestionTypeIndex)
                                .replace("{{no}}", ++jcount)
                                .myReplace("{{id}}", rel.rows[i].eq_id)
                                .replace("{{answer}}", rel.rows[i].answer)
                        );
                    } else {
                        chosehtml.push(
                            cHtml.replace("{{question}}", rel.rows[i].question)
                                .replace("{{answerA}}", rel.rows[i].op_a)
                                .replace("{{answerB}}", rel.rows[i].op_b)
                                .replace("{{answerC}}", rel.rows[i].op_c)
                                .replace("{{answerD}}", rel.rows[i].op_d)
                                .replace("{{no}}", ++cCount)
                                .myReplace("{{id}}", rel.rows[i].eq_id)
                                .replace("{{answer}}", rel.rows[i].answer)
                        );
                    }


                }
                $("#choseList").html(chosehtml.join(""));
                $("#judgeList").html(html.join(""));

            });

        });


        function uploadTest() {
            for (var i = 0; i < questions.length; i++) {

                console.log($("input[type=radio][name=radio_" + questions[i].eq_id + "]:checked").val());
                var answer = $("input[type=radio][name=radio_" + questions[i].eq_id + "]:checked").val();
                if (answer !== undefined) {
                    console.log(answer)
                    console.log("答案" + questions[i].answer)
                    $("p#answer_" + questions[i].eq_id).text("答案 " + questions[i].answer).show();
                    if (answer == questions[i].answer) {
                        $("img#img_" + questions[i].eq_id).attr("src", "../img/dui.png").show();
                    } else {
                        $("img#img_" + questions[i].eq_id).attr("src", "../img/wrong.png").show();
                    }
                }

            }
        }
        function getPanduanQuestionTypeIndex(list) {
            var index = "一"
            for (var i = 0; i < list.length; i++) {
                console.log(list[i])
                if (list[i].eqt_id === 2) { //只要有一个选择题, 那么就是一
                    index = "二"
                }
            }
            console.log(index)
            return index
        }

    </script>

</body>

</html>